package com.umpay.utils.mail;

import javax.mail.PasswordAuthentication;

/**
 * 重写邮件鉴权类
 * 注意需要设置 SMTP 需要验证
 *  mail.smtp.auth = true
 *
 */
public class Authenticator extends javax.mail.Authenticator {
	
	//用户名
	String smtpuser = "";
	//密码
	String smtppwd = "";
	public Authenticator(){
		
	}
	//赋值用户名密码
	public Authenticator(String smtpuser,String smtppwd) {
		this.smtpuser = smtpuser;
		this.smtppwd = smtppwd;
	}
	/**
	 * 这是javamail的验证方法中
	 * 重写Authenticator的getPasswordAuthentication()方法
	 * 用来解决javax.mail.AuthenticationFailedException异常
	 */
	public PasswordAuthentication getPasswordAuthentication() {
		return new PasswordAuthentication(smtpuser, smtppwd);
	}

}
